package com.oocl.customer.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.customersystem.pojo.Order;
import com.oocl.customersystem.util.RequestUtil;

/**
 * Servlet implementation class DeleteOrders
 */
public class DeleteOrders extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("foodName");
		Map<String,Order> cart = (Map<String, Order>) request.getSession().getAttribute("cart");
		cart.remove(name);
		request.getSession().setAttribute("cart", cart);
		List<Order> list =new  ArrayList<Order>();
		Set<String> set = cart.keySet();
		for(String fname:set){
			list.add(cart.get(fname));
		}
		String json = RequestUtil.wrapToJson(list);
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().write(json);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
